﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using SnakeGame.ViewModels;

namespace SnakeGame.Views
{
    /// <summary>
    /// Interaction logic for JudgePage.xaml
    /// </summary>
    public partial class JudgePage : Page
    {
        private JudgePageViewModel _judgePageViewModel;
        private QuestionFrame _frame;
        public JudgePage()
        {
            InitializeComponent();
        }

        public void Initialize(QuestionFrame qf)
        {
            _frame = qf;
            _judgePageViewModel = new JudgePageViewModel();
            DataContext = _judgePageViewModel;
            _judgePageViewModel.Initialize(qf);
        }

        private void Page_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == Key.Y)
            {
                _judgePageViewModel.CorrectCommand.Execute(sender);
            }
            else if (e.Key == Key.N)
            {
                _judgePageViewModel.WrongCommand.Execute(sender);
            }
        }

        private void JudgePage_OnLoaded(object sender, RoutedEventArgs e)
        {
            _frame.Window.KeyDown += Page_KeyDown;
        }

        private void Page_Unloaded(object sender, RoutedEventArgs e)
        {
            _frame.Window.KeyDown -= Page_KeyDown;
        }
    }
}
